import { list2Obj } from '@/pages/supplier/utils'

const INITIAL_REGULAR_PRICE_FIELDS_VALUE = {
  adjustmentAmount: undefined,
  adjustmentNo: '',
  balance: undefined,
  checkArea: undefined,
  checkAreaCode: '',
  checkAreaName: '',
  contactPhone: '',
  createUser: '',
  createUserId: undefined,
  hasAdjustment: undefined,
  manageArea: undefined,
  manageAreaName: '',
  processBillId: undefined,
  questionLevel: undefined,
  questionType: undefined,
  remittanceCertificate: '',
  specificCauses: undefined,
  supplierCode: '',
  supplierId: undefined,
  supplierLevel: undefined,
  supplierName: ''
}
const INITIAL_TEMP_PRICE_FIELDS_VALUE = {
  adjustmentAmount: undefined,
  adjustmentNo: '',
  companyId: undefined,
  companyName: '',
  organizeType: undefined,
  contactPerson: '',
  contactPhone: '',
  createUser: '',
  createUserId: undefined,
  hasAdjustment: undefined,
  hasPriceQuestion: undefined,
  invoiceSupplierId: undefined,
  invoiceSupplierName: '',
  processBillId: undefined,
  purchaseBill: '',
  purchasePerson: undefined,
  purchasePersonName: '',
  purchasePersonNo: '',
  remittanceCertificate: '',
  supplierCode: '',
  supplierId: undefined,
  supplierName: '',
  spotCheckDesc: '',
}
const REGULAR_PRICE_TABLE_COLUMNS = [
  { field: 'productCode', title: '商品代码', minWidth: 100, editRender: { enabled: false } },
  { field: 'productName', title: '商品名称', minWidth: 160 },
  { field: 'specification', title: '规格', minWidth: 120 },
  { field: 'unit', title: '单位', minWidth: 100 },
  { field: 'lastYearPurchaseCount', title: '上年度进货数量', minWidth: 120 },
  { field: 'lastYearPurchaseAmount', title: '上年度进货金额', minWidth: 120 },
  { field: 'thisYearPurchaseCount', title: '本年度采购数量', minWidth: 120 },
  { field: 'thisYearPurchaseAmount', title: '本年度采购金额', minWidth: 120 },
  { field: 'price', title: '进价', minWidth: 160, },
  { field: 'checkPrice', title: '核查价格', minWidth: 160, editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' }, },
  { field: 'priceRatio', title: '价格比例', minWidth: 120, },
  { field: 'otherSupplierPrice', title: '其他供应商进价', minWidth: 120, type: 'float', editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' } },
  { field: 'otherSupplierPriceRatio', title: '其他供应商价格比例', minWidth: 130, },
  { field: 'otherSupplierName', title: '其他供应商名称', minWidth: 120, type: 'text', maxlength: 200, editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' } },
]

const TEMP_PRICE_TABLE_COLUMNS = [
  { field: 'productCode', title: '商品代码', minWidth: 100 },
  { field: 'productName', title: '商品名称', minWidth: 140 },
  { field: 'specification', title: '规格', minWidth: 80 },
  { field: 'unit', title: '单位', minWidth: 80 },
  {
    field: 'purchaseCount',
    title: '订货数量',
    minWidth: 160,
    editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' },
  },
  {
    field: 'purchasePrice',
    title: '订货价格',
    minWidth: 160,
    editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' },
  },
  { field: 'totalAmount', title: '金额总计', minWidth: 160, },
  {
    field: 'checkPrice',
    title: '核查价格',
    minWidth: 160,
    editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' },
  },
  { field: 'balance', title: '差额', minWidth: 160, },
  { field: 'priceRatio', title: '差率', minWidth: 160, },
  { field: 'otherSupplierPrice',
    title: '其他供应商价格',
    minWidth: 160,
    editRender: { placeholder: '请点击输入...', autofocus: '.vxe-input--inner' },
  },
  { field: 'otherSupplierBalance', title: '其他供应商差额', minWidth: 160, },
]
// 问题原因
const QUESTION_REASON_OPTIONS = [
  { value: 0, label: '渠道选择不合理' },
  { value: 1, label: '渠道优化不及时' },
  { value: 2, label: '有降价空间被动调整（人员责任心）' },
  { value: 3, label: '厂家针对性报价（我司原因导致）' },
  { value: 4, label: '厂家针对性报价（厂家恶意）' },
  { value: 5, label: '政策差异（促销、返利）' },
  { value: 6, label: '有降价空间被动调整（厂家恶意）' },
  { value: 7, label: '厂家策略性报价（新客户）' },
]
const QUESTION_REASON_MAP_OBJECT = list2Obj(QUESTION_REASON_OPTIONS)

// 问题错误类型(临采)
const QUESTION_TYPE_OPTIONS = [
  { value: 0, label: '无问题' },
  { value: 1, label: '明知故犯型' },
  { value: 2, label: '缺乏责任心型' },
  { value: 3, label: '操作失误型' },
  { value: 4, label: '不够完美型' },
]
const QUESTION_TYPE_MAP_OBJECT = list2Obj(QUESTION_TYPE_OPTIONS)

// 问题等级
const QUESTION_LEVEL_OPTIONS = [
  { value: 1, label: '无问题' },
  { value: 2, label: '一般' },
  { value: 3, label: '严重' },
  { value: 4, label: '非常严重' },
]
const QUESTION_LEVEL_MAP_OBJECT = list2Obj(QUESTION_LEVEL_OPTIONS)

const SUPPLIER_LEVEL_MAP_OBJECT = {
  '54': 'S',
  '55': 'A',
  '56': 'B',
  '59': 'D',
  '807': 'C',
}
const getTableColumns = (type) => {
  if (type === 'temp') {
    return TEMP_PRICE_TABLE_COLUMNS
  }
  return REGULAR_PRICE_TABLE_COLUMNS
}
const getInitialFieldsValue = (type) => {
  if (type === 'temp') {
    return INITIAL_TEMP_PRICE_FIELDS_VALUE
  }
  return INITIAL_REGULAR_PRICE_FIELDS_VALUE
}

export default {
  getTableColumns,
  getInitialFieldsValue,
  QUESTION_REASON_OPTIONS,
  QUESTION_REASON_MAP_OBJECT,
  QUESTION_TYPE_OPTIONS,
  QUESTION_TYPE_MAP_OBJECT,
  QUESTION_LEVEL_OPTIONS,
  QUESTION_LEVEL_MAP_OBJECT,
  SUPPLIER_LEVEL_MAP_OBJECT,
}
